import {
  tokenKey
} from '@/config'

const state = () => ({
  token: uni.$u.getStorage(tokenKey),
})
const mutations = {
  SET_TOKEN: (state, token) => {
    state.token = token
    uni.$u.setStorage(tokenKey, token)
  },
}
const actions = {
  Login: ({
    commit
  }) => {
    setTimeout(() => {
      commit('SET_TOKEN', 'token:123456789')
    }, 1000)
  },
  LogOut: ({
    commit
  }) => {
    setTimeout(() => {
      commit('SET_TOKEN', '')
      uni.$u.clearStorage()
    }, 1000)
  },
}

export default {
  state,
  mutations,
  actions
}